package cn.xopencode.recordservice.dal.mysql.mapper.sf6machine;

import cn.xopencode.mybatis.core.query.QueryWrapperX;
import cn.xopencode.recordservice.dal.mysql.dataobject.sf6machine.Sf6MachineRecordDetailDO;
import cn.xopencode.recordservice.service.sf6machine.bo.Sf6MachineRecordNextCreateBO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;

@Repository
public interface Sf6MachineRecordDetailMapper extends BaseMapper<Sf6MachineRecordDetailDO> {

    default Sf6MachineRecordDetailDO getSf6MachineRecordDetailByRecordCodeAndNum(Sf6MachineRecordNextCreateBO nextCreateBO){
        return selectOne(new QueryWrapperX<Sf6MachineRecordDetailDO>()
                .eqIfPresent("record_code", nextCreateBO.getRecordCode())
                .eqIfPresent("pdroom_id", nextCreateBO.getPdroomId()));
    }

    default Sf6MachineRecordDetailDO getFirstSf6MachineRecordDetailByRecordCode(String recordCode, Integer recordSeq){
        return selectOne(new QueryWrapperX<Sf6MachineRecordDetailDO>()
                .eqIfPresent("record_code", recordCode)
                .eqIfPresent("record_seq", recordSeq)
        );
    }

    default Integer selectNeedNoticeLeaderCountByRecordCode(String recordCode){
        return selectCount(new QueryWrapperX<Sf6MachineRecordDetailDO>()
                .eqIfPresent("record_code", recordCode)
                .eq("is_notice_leader", 1)
        );
    }

    default Integer selectNeedLeaderDealCountByRecordCode(String recordCode){
        return selectCount(new QueryWrapperX<Sf6MachineRecordDetailDO>()
                .eqIfPresent("record_code", recordCode)
                .eq("is_notice_leader", 1)
                .eq("is_leader_deal", 0)
        );
    }
}
